Fix memory leak by freeing ret before error handling#267
Open
odaysec wants to merge 2 commits intoWebKit:mainfrom
Open
Fix memory leak by freeing ret before error handling#267odaysec wants to merge 2 commits intoWebKit:mainfrom
odaysec wants to merge 2 commits intoWebKit:mainfrom
Conversation
✅ Deploy Preview for webkit-jetstream-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix avoid accessing any members of
retafter callingfree(ret). Iftsf_type_destroymust be called onret->type, do so before freeingret, or copyret->typeinto a local variable before freeingretand then destroy that local variable.Best concrete fix here: On the error path in the
TSF_TK_STRUCTcase where allocation ofret->u.c.arrayfails, reorder the cleanup so thattsf_type_destroy(ret->type)is called beforefree(ret). This ensures there is no member access through a freed pointer, while preserving the existing behavior and error reporting. No new headers or helper functions are required.Specific changes:
wasm/TSF/tsf_reflect.c, insidetsf_reflect_create, locate thecase TSF_TK_STRUCT:branch.if (ret->u.c.array == NULL)error block, movetsf_type_destroy(ret->type);to appear beforefree(ret);, or equivalently, swap lines 93 and 94.tsf_type_destroy(ret->type);free(ret);tsf_set_errno(...);return NULL;